package com.sfh.cp.user.login;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.widget.EditText;

import com.sfh.cp.R;
import com.sfh.cp.base.AbstractBaseActivity;
import com.sfh.cp.user.ReqRegister;
import com.sfh.cp.user.pst.IPstLogin;
import com.sfh.cp.user.pst.IPstRegister;
import com.sfh.lib.mvp.IPresenter;
import com.sfh.lib.mvp.service.LoaderService;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 功能描述:注册
 *
 * @date 2018/3/12
 */
public class UserRegisterActivity extends AbstractBaseActivity implements IPstRegister.IVRegister {



    public static void startUI(Context context) {
        Intent intent = new Intent(context, UserRegisterActivity.class);
        context.startActivity(intent);
    }

    @BindView(R.id.etName)
    EditText etName;
    @BindView(R.id.etPwd)
    EditText etPwd;
    IPstRegister pstLogin;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.user_register_activity);
        ButterKnife.bind(this);

    }


    @Override
    public IPresenter getPresenter() {
        if (pstLogin == null) {
            pstLogin = LoaderService.getService(IPstRegister.class);
        }
        return pstLogin;
    }


    @OnClick(R.id.btnLogin)
    public void onViewClicked() {
        if (pstLogin == null) {
            return;
        }
        ReqRegister req = new ReqRegister();
        req.setPhone(etName.getText().toString());
        req.setPassword(etPwd.getText().toString());
        pstLogin.register(req);
    }

    @Override
    public void onSuccess() {

        showToast("注册成功");
        finish();
    }
}
